package su2010.puz.extractors;

import java.awt.image.BufferedImage;

import su2010.puz.Extractor;
import su2010.puz.Filter;
import su2010.puz.impl.CannyEdgeFilter;
import su2010.puz.impl.SharpenFilter;
import su2010.puz.impl.SobelEdgeFilter;
import su2010.puz.util.ImageCls;
import su2010.puz.util.PixelExtractor;

public class ColorExtractor implements Extractor {

	private BufferedImage image;
	private int numOutput = 1;
	private String name = "Color Sobel Pixel Ratio";
	
	@Override
	public float[] extract() {
		int w = image.getWidth();
		int h = image.getHeight();
		int[] pixels = new int[h*w];
		PixelExtractor.getRGB(image, 0, 0, w, h, pixels);
		double color = 0;
		for(int i = 0; i< h*w;i++)
			color += pixels[i];
//		System.out.println(color);
		
		BufferedImage img = new SobelEdgeFilter().apply(new SharpenFilter().apply(image));
		int w1 = img.getWidth();
		int h1 = img.getHeight();
		int[] pixels1= new int[h1*w1];
		PixelExtractor.getRGB(img, 0, 0, w1, h1, pixels1);
		double color1 = 0;
		for(int i = 0; i< h1*w1;i++)
			if(pixels1[i] != -16777216)
				color1 += pixels1[i];
		color1*=-1;
//		System.out.println(color1);
//		System.out.println(color1/color);
		return new float[]{(float)(color1/color)};
	}

	@Override
	public int getNumOutput() {
		return numOutput;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setImage(ImageCls image) {
		this.image = image.getImage();
	}

}
